//
// Created by nilyang on 2021/11/28.
//

#include <cassert>
#include "class_invariant.h"

void Snake::Invariant() const {
    assert(loc.x >= 0 && loc.x <= play_width);
    assert(loc.y >= 0 && loc.y <= play_height);
}

Snake::Snake(int _w, int _h, Pos _p) :
        play_width{_w}, play_height{_h}, loc{_p} {
    Invariant();
}

void Snake::TeleportAhead(Pos inc) {
    loc.x += inc.x;
    loc.y += inc.y;
    Invariant();
}

Pos Snake::GetLoc() {
    return loc;
}

void func_invariant() {
    Snake snake(30, 20, Pos(5, 5));
    snake.TeleportAhead(Pos(20, 20));
    Snake snake2(10, 10, Pos(12, 8));
}
